package b_openApi管理.c_查询RID信息;

import a_接口调用凭证.a_获取接口调用凭据.GetAccessToken;
import b_openApi管理.b_查询API调用额度.GetQuota;
import com.fasterxml.jackson.annotation.JsonProperty;
import my.wechat.rc.common.HttpClientUtil;
import my.wechat.rc.common.MapUtil;

/**
 * @author 86153
 * @date 2022/7/30
 **/
public class GetRidInfo {

    public static GetRidInfoResponse getRidInfo() {
        try {
            String rid = GetQuota.getQuota("/a/b/c").getErrmsg().split("rid:")[1].trim();
            Thread.sleep(10000);//太快查询不到rid
            String url = "https://api.weixin.qq.com/cgi-bin/openapi/rid/get?access_token=" + GetAccessToken.getAccessToken().getAccessToken();
            return HttpClientUtil.post(url, MapUtil.of("rid", rid), GetRidInfoResponse.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new GetRidInfoResponse();
    }

    public static void main(String[] args) {
        getRidInfo();
    }

    public static class GetRidInfoResponse {
        private Integer errcode;
        private String errmsg;
        private GetRidInfoResponseRequest request;

        public Integer getErrcode() {
            return errcode;
        }

        public void setErrcode(Integer errcode) {
            this.errcode = errcode;
        }

        public String getErrmsg() {
            return errmsg;
        }

        public void setErrmsg(String errmsg) {
            this.errmsg = errmsg;
        }

        public GetRidInfoResponseRequest getRequest() {
            return request;
        }

        public void setRequest(GetRidInfoResponseRequest request) {
            this.request = request;
        }

        public static class GetRidInfoResponseRequest {
            @JsonProperty("invoke_time")
            private Integer invokeTime;//发起请求的时间戳
            @JsonProperty("cost_in_ms")
            private Integer costInMs;//请求毫秒级耗时
            @JsonProperty("request_url")
            private String requestUrl;//请求的 URL 参数
            @JsonProperty("request_body")
            private String requestBody;//post请求的请求参数
            @JsonProperty("response_body")
            private String responseBody;//接口请求返回参数
            @JsonProperty("client_ip")
            private String clientIp;//接口请求的客户端ip

            public Integer getInvokeTime() {
                return invokeTime;
            }

            public void setInvokeTime(Integer invokeTime) {
                this.invokeTime = invokeTime;
            }

            public Integer getCostInMs() {
                return costInMs;
            }

            public void setCostInMs(Integer costInMs) {
                this.costInMs = costInMs;
            }

            public String getRequestUrl() {
                return requestUrl;
            }

            public void setRequestUrl(String requestUrl) {
                this.requestUrl = requestUrl;
            }

            public String getRequestBody() {
                return requestBody;
            }

            public void setRequestBody(String requestBody) {
                this.requestBody = requestBody;
            }

            public String getResponseBody() {
                return responseBody;
            }

            public void setResponseBody(String responseBody) {
                this.responseBody = responseBody;
            }

            public String getClientIp() {
                return clientIp;
            }

            public void setClientIp(String clientIp) {
                this.clientIp = clientIp;
            }
        }
    }
}
